package com.wen.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wen.pojo.Product;
import com.wen.pojo.dto.ProductAndStockDetails;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xie
 */
public interface ProductMapper extends BaseMapper<Product> {


    @Select("SELECT * FROM `stock_details` sd INNER JOIN `product` p WHERE sd.`product_id` = p.`id` AND p.`id` = #{id}")
    List<ProductAndStockDetails> selProductAndStockDetails(String id);

    @Update("UPDATE `product` SET `inventory`= `inventory` + #{stock} WHERE `id`= #{id}\n")
    int updateProduct(@Param("stock") String stock, @Param("id") String id);

    @Update("UPDATE `product` SET `inventory` = `inventory`  -   #{count} WHERE `id` = #{pid}")
    int  UpdateCount  (@Param("count") Integer count, @Param("pid") String pid);



}
